<%@ page language="java" import="java.util.*,ms.platform.system.model.*"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<title>用户列表</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
<script type="text/javascript" src="<%=basePath%>js/common/jquery-2.1.0.js"  charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js"  charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/delete.js"></script>	
<script type="text/javascript">
		$(document).ready(function(){
			//禁用
			
			$("span[name='disabledAdmin']").click(function(){
			  var id=$(this).parent().attr("id");
			  var isUsed=$(this).attr("isUsed");
			  var grayScreen=document.getElementById("gray-screen");
			  console.info("grayScreen:"+grayScreen);
			  console.info("id:"+id);
			  console.info("isUsed:"+isUsed);
	           $.ajax({            
	                  type:"post",
	                  url:"<%=path%>/system/admin/disabledAdmin", 
	                  data:"id="+id+"&isUsed="+isUsed,  
	                  dataType:"json",
	                  success:function(data) {
	                	  if(data.message != undefined){
	                		  Dialog({
			  		                "msg": '<div class="D_alert">'+data.message+'</div>',
			  		                "title": "提示",
			  		                "showButtons": true,
			  		                "cancelButton": false,
			  		                "onComplete": function() {
			  		                	grayScreen.style.display="none";
			  		                	window.location.reload();
			  		                }
			  		          });
		                	  
							if(isUsed=="1"){
								$("#"+id).parent().find(".isUsedId").html("启用");
								$(this).attr("isUsed",0);
								$(this).html("禁用");
							}else{
								$("#"+id).parent().find(".isUsedId").html("<span style='color: red'>禁用</span>");
								$(this).attr("isUsed",1);
								$(this).html("启用");
							}
	                	  }else{
	                		  window.location.reload();
	                	  }
	                	  
	                  }            
	            });  
			});
			
			//获取删除用户的ID 添加到隐藏域
			$("span[name='deleteUser']").click(function(){
			       var id=$(this).parent().attr("id");
			       $(".hiddenId").val(id);
				});
			//删除用户
			$("#deleteDict").on("click",function(e){
				var id=$(".hiddenId").val();
				deleteList.hiddenId("<%=path%>/system/admin/deleteUser","<%=path%>/system/admin/list",("id="+id));
				
			});
			
			//跳转到添加页面
			$(".addAdmin").click(function(){
				  window.location.href="<%=path%>/system/admin/toAdd";
			});
			
			//跳转到编辑页面
			$("span[name='editAdmin']").click(function(){
				  var id=$(this).parent().attr("id");
				  window.location.href="<%=path%>/system/admin/toEdit?id="+id;
			});
			//跳转到密码修改页面
			$("span[name='editPassword']").click(function(){
				  var id=$(this).parent().attr("id");
				  window.location.href="<%=path%>/system/admin/toEditPassword?id="+id;
			});
			//跳转到添加页面
			$(".sha").click(function(){
				  window.location.href="<%=path%>/system/admin/sha";
			});
			
			//清空搜索条件
			$(".clearForm").click(function(){
				$("#queryForm").find("input").val("");
				$("#queryForm").find("select").val("");
			});
			
			//提交表单
			<%--$(".queryForm").click(function(){--%>
				 <%--var data=$("#queryForm").serialize();--%>
				<%--window.location.href="<%=path%>/system/admin/list?"+data;--%>
			<%--});--%>

			
			//全选/非全选角色
			$("input[name='allCheckbox']").click(function(){
				if($(this).prop("checked")){
					$("input[name='roleCheckbox']").prop("checked",true);
					$(this).attr("operation","operation");
				}else{
					$("input[name='roleCheckbox']").prop("checked",false);
					$(this).attr("operation","operation");
				}					
				
			});
			
			$("input[name='roleCheckbox']").click(function() {
				$(this).attr("operation","operation");
				$("input[name='allCheckbox']").prop("checked",false);
			});
			
			//给用户分配角色
			$("#allotUserRole").click(function(){
				var str="";
				var type=0;
				$("input[name='roleCheckbox']").each(function() {
					if ($(this).prop("checked") == true	|| $(this).prop("checked") == "checked") {
						type=1;
					}else{
						type=0;
					}
					if (str == "") {
						str = $(this).val()+"-"+type;
					} else {
						str = str + ","	+ $(this).val()+"-"+type;
					}
				});
				
				  var id=$("#myModal").attr("adminId");
				  $.ajax({            
	                  type:"post",
	                  url:"<%=path%>/system/role/allotRole", 
	                  data:"adminId="+id+"&roleIds="+str, 
	                  dataType:"json",
	                  success:function(data) {
	                	  showMessage(data.message);
	                	  $(".D_submit").click(function(){
		                	  $("#myModal").hide();
		                	  $(".modal-backdrop").removeClass("modal-backdrop fade in");
		                	  document.location.reload();
	                	  })
	                  }
				  }); 
			});
			
			//打开分配角色面板
			$("span[name='toAllotRole']").click(function(){
				//确认用户是否禁用，如果禁用则不能打开面板
				var isUseded =  $(this).parent().find('span').eq(0).attr('isUsed');
				//console.info(isUseded);
				if(isUseded=="1"){
					showMessage("当前用户状态为禁用，请点击启用");
					return;
				}else {
					/* $("#myModal").modal('show'); */
					  $("#myModal").find(":checkbox").prop("checked",false);
				        var id=$(this).parent().attr("id");
				        $("#myModal").attr("adminId",id);
				        $.ajax({            
			                  type:"post",
			                  url:"<%=path%>/system/role/toAllotRole", 
			                  data:"id="+id, 
			                  dataType:"json",
			                  success:function(data) {
			                	var ids = data.data;
								if(ids!=null && ids!=""){
									var strs= new Array(); 
									strs=ids.split(","); 
									for (i=0;i<strs.length;i++) { 
										$("input[name='roleCheckbox']").each(function() {
											if ($(this).val()==strs[i]) {
												$(this).prop("checked",true);
											}
										});
									}
								}
			                  }            
			            }); 
				}
				 
			});
			
		});
    </script>
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"> </span><span id="arrows-left">首页</span> 
					<span id="arrows-left">></span><span>系统管理</span> 
					<span id="arrows-left">></span><span>用户管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12">
							<form role="form" id="queryForm" method="post" action="<%=path%>/system/admin/list">
								<table class="textTable">
									<tr>
										<td class="platform-start">姓名:</td>
										<th class=""><input type="text" class="Wdate form-control input-sm" name="username" value="${map['username'] }"></th>	
										<td class="platform-start">手机:</td>
										<th class=""><input type="text" class="Wdate form-control input-sm" name="phone" value="${map['phone'] }"></th>
										<td class="platform-start">邮箱:</td>
										<th class=""><input type="text" class="Wdate form-control input-sm" name="email" value="${map['email'] }"></th>
										
									</tr>
									<tr>
									</tr>
								</table>
								<ul class="textBtn">
								   <li class="">
								   		<!-- <button type="button" class="sha btn btn-primary btn-sm">密码加密</button>
								   		 --><button type="submit" class="search-form-btn-s btn btn-primary btn-sm">查询</button>
										<button type="button" class="clearForm btn btn-primary btn-sm">重置</button>
										<button type="button" class="addAdmin btn btn-primary btn-sm">添加</button>
									</li>
								</ul>
							</form>
							<table class="control-tatle table table-striped table-bordered table-hover" action="<%=path%>/system/admin/list">
								<thead class="financing-thead">
									<tr>
										<th style="width: 5%">序号</th>
										<th style="width: 8%">姓名</th>
										<th style="width: 8%">座机</th>
										<th style="width: 8%">手机</th>
										<th style="width: 15%">邮箱</th>
										<th style="width: 15%">所属组织</th>
										<th style="width: 5%">状态</th>
										<th style="width: 15%">创建时间</th>
										<th style="width: 25%">操作</th>
									</tr>
								</thead>
								<tbody>
									<c:if test="${not empty list}">
										<c:forEach items="${list }" var="admin" varStatus="r">
											<tr>	
												<td>${r.index+1 }</td>
												<td>${admin.username }</td>
												<td>${admin.mobile }</td>
												<td>${admin.phone }</td>
												<td>${admin.email }</td>
												<td>${admin.orgId }</td>
												<td class="isUsedId">
													<c:if test="${admin.isUsed==1 }">启用</c:if> 
			                            			<c:if test="${admin.isUsed==0 || admin.isUsed==2  }"><span style="color: red">禁用</span></c:if>
												</td>
												<td><fmt:formatDate value="${admin.createDate }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
												<td id="${admin.id }">
													<c:if test="${admin.isUsed==1 }">
														<span class="span1" name="disabledAdmin" isUsed=0>禁用</span>
													</c:if> 
													<c:if test="${admin.isUsed==0 }">
														<span class="span1" name="disabledAdmin" isUsed=1>启用</span>
													</c:if> 
													<span name="editAdmin" class="span1">编辑</span>
													<span name="editPassword" class="span1">修改密码</span> 
													<span name="deleteUser" data-toggle='modal' data-target='#bxModal' class="span1">删除</span> 
													<span name="toAllotRole" data-toggle="modal" data-target="#myModal" class="span1" >分配角色</span>
												</td>
												<input type="hidden" class="hiddenId" value="">
											</tr>
										</c:forEach>
									</c:if>
									<c:if test="${empty list}">
										<tr>
											<td colspan="10"><label class="control-label text-center">无记录</label></td>
										</tr>
									</c:if>
								</tbody>
										<tr style="background:#f8f8f8">
											<td colspan="10"><jsp:include page="/WEB-INF/jsp/page.jsp"></jsp:include></td>
										</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- 分配角色面板 start -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true" adminId>
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">分配角色</h4>
					</div>
					<div class="modal-body">
						<div class="checkbox">
							<label><input type="checkbox" name="allCheckbox">全选</label>
						</div>
						<c:forEach items="${roleList }" var="role">
							<div class="checkbox">
								<label><input type="checkbox" name="roleCheckbox" value="${role.id }">${role.roleName }</label>
							</div>
						</c:forEach>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" id="allotUserRole">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 分配角色面板end -->
		<!-- 删除弹框 start -->
						<div class="modal fade" id="bxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
						     <div class="modal-dialog modal-tbxb" style=" top:50%; margin-top:-5%;">
						          <div class="modal-content" >
						               <div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">提示</h4>
									   </div>
									   <div class="modal-body">
									       <div class="form-group financialRisk" style="text-align:center;">
												是否确认删除？
								          </div>
								          <ul class="col-btn-12">
											<li>
												<button class="btn-primary btn" id="deleteDict" data-dismiss="modal" aria-hidden="true">确认</button>
												<button type="button" class="btn-default btn" data-dismiss="modal" aria-hidden="true">取消</button>
											</li>
										</ul>
									   </div>
						          </div>
						     </div>
						</div>
						<!-- 删除弹框 end -->
						<!-- 提示弹框 start -->
					<!-- 	<div class="modal fade" id="bxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
						     <div class="modal-dialog modal-tbxb" style=" top:50%; margin-top:-5%;">
						          <div class="modal-content" >
						               <div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">提示</h4>
									   </div>
									   <div class="modal-body">
									       <div class="form-group financialRisk" style="text-align:center;">
												
								          </div>
								          <ul class="col-btn-12">
											<li>
												<button class="btn-primary btn" id="" data-dismiss="modal" aria-hidden="true">确认</button>
											</li>
										</ul>
									   </div>
						          </div>
						     </div>
						</div> -->
						<!-- 提示弹框 end -->
	</div>
	<div id="gray-screen"></div>
</body>

</html>
